<?php
namespace App\Repositories\Main;

use App\Models\Main\MsgDetailModel;
use App\Repositories\BaseRepository;

class MsgDetailRepository extends BaseRepository
{
    protected $repository;

    public function __construct()
    {
        $this->repository = new MsgDetailModel();
    }

    public function getIndexList(){
        return $this->repository
            ->orderBy('id','asc')
            ->skip(0)
            ->take(10)
            ->get();
    }

    public function getIndexByTalk($talk,$from){
        return $this->repository
            ->where([
                ['talk','=',$talk],
                ['from','=',$from],
            ])->orderBy('id','asc')
//            ->skip(0)
//            ->take(10)
            ->get();
    }

    public function setAdd($talkId,$from,$detail)
    {
        $dataArr = array(
            'talk' => $talkId,
            'from' => $from,
            'detail' => $detail,
            'created_at' => time(),
        );
        return $this->repository->insertGetId($dataArr);
    }

    /**
     * 设置已读时间
     */
    public function setStatus($ids)
    {
        return $this->repository
            ->whereIn('id',$ids)
            ->where('status',1)
            ->update(array(
                'status' => 2,
                'updated_at' => time(),
            ));
    }
}